package com.ruoyi.safe.controller.web;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.safe.domain.BizSafeInfor;
import com.ruoyi.safe.domain.dto.BizSafeInfoCoverAttachDTO;
import com.ruoyi.safe.domain.dto.BizSafeInforAppendAttachDTO;
import com.ruoyi.safe.domain.dto.BizSafeInforFileListDTO;
import com.ruoyi.safe.domain.dto.BizSafeInforRelateCatalogDTO;
import com.ruoyi.safe.domain.vo.BizSafeDocAttachVO;
import com.ruoyi.safe.service.IBizSafeInforService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 安全内业资料Controller
 * 
 * @author ruoyi
 * @date 2024-01-10
 */
@RestController
@RequestMapping("/infor/infor")
public class BizSafeInforController extends BaseController
{
    @Autowired
    private IBizSafeInforService bizSafeInforService;

    /**
     * 查询安全内业资料列表
     */
    @PreAuthorize("@ss.hasPermi('infor:infor:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizSafeInfor bizSafeInfor)
    {
        startPage();
        List<BizSafeInfor> list = bizSafeInforService.selectBizSafeInforList(bizSafeInfor);
        return getDataTable(list);
    }

    /**
     * 导出安全内业资料列表
     */
    @PreAuthorize("@ss.hasPermi('infor:infor:export')")
    @Log(title = "安全内业资料", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizSafeInfor bizSafeInfor)
    {
        List<BizSafeInfor> list = bizSafeInforService.selectBizSafeInforList(bizSafeInfor);
        ExcelUtil<BizSafeInfor> util = new ExcelUtil<BizSafeInfor>(BizSafeInfor.class);
        util.exportExcel(response, list, "安全内业资料数据");
    }

    /**
     * 获取安全内业资料详细信息
     */
    @PreAuthorize("@ss.hasPermi('infor:infor:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizSafeInforService.selectBizSafeInforById(id));
    }

    /**
     * 新增安全内业资料
     */
    @PreAuthorize("@ss.hasPermi('infor:infor:add')")
    @Log(title = "安全内业资料", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizSafeInfor bizSafeInfor)
    {
        return toAjax(bizSafeInforService.insertBizSafeInfor(bizSafeInfor));
    }

    /**
     * 修改安全内业资料
     */
    @PreAuthorize("@ss.hasPermi('infor:infor:edit')")
    @Log(title = "安全内业资料", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizSafeInfor bizSafeInfor)
    {
        return toAjax(bizSafeInforService.updateBizSafeInfor(bizSafeInfor));
    }

    /**
     * 删除安全内业资料
     */
    @PreAuthorize("@ss.hasPermi('infor:infor:remove')")
    @Log(title = "安全内业资料", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bizSafeInforService.deleteBizSafeInforByIds(ids));
    }

    /**
     * 获取项目下的安全内业资料
     * @param projectId
     * @return
     */
    @GetMapping("/list/{projectId}")
    public AjaxResult getListByProjectId(@PathVariable("projectId") Long projectId){
        List<BizSafeInfor> list = bizSafeInforService.selectListByProjectId(projectId);
        return AjaxResult.success(list);
    }

    /**
     * 新建下级
     * @param parentId
     * @param bizSafeInfor
     * @return
     */
    @PostMapping("/createJunior/{parentId}")
    public AjaxResult createJunior(@PathVariable Long parentId,@RequestBody BizSafeInfor bizSafeInfor){
        return AjaxResult.success(bizSafeInforService.createJunior(parentId,bizSafeInfor));
    }
    /**
     * 引用目录模板
     * @param bizSafeInforRelateCatalogDTO
     * @return
     */
    @PostMapping("/relateCatalog")
    public AjaxResult relateCatalog(@RequestBody BizSafeInforRelateCatalogDTO bizSafeInforRelateCatalogDTO){
        return toAjax(bizSafeInforService.relateCatalog(bizSafeInforRelateCatalogDTO));
    }

    /**
     * 一级目录下资料上传情况
     * @param projectId
     * @return
     */
    @GetMapping("/statistic/firstLevel/{projectId}")
    public AjaxResult firstLevelSafeInforStatistics(@PathVariable Long projectId){
        return success(bizSafeInforService.firstLevelSafeInforStatistics(projectId));
    }

    /**
     * 整个项目下资料上传情况
     * @param projectId
     * @return
     */
    @GetMapping("/statistic/{projectId}")
    public AjaxResult safeInforStatistics(@PathVariable Long projectId){
        return success(bizSafeInforService.safeInforStatistics(projectId));
    }

    /**
     * 项目下每个目录的资料完成情况
     * @param projectId
     * @return
     */
    @GetMapping("/performance/{projectId}")
    public AjaxResult performance(@PathVariable Long projectId){
        return success(bizSafeInforService.performance(projectId));
    }
    /**
     * 重新关联目录详情和附件
     * @param bizSafeInforAppendAttachDTO
     * @return
     */
    @PostMapping("/relateAttaches")
    public AjaxResult relateSafeDocAttaches(@RequestBody @Validated BizSafeInforAppendAttachDTO bizSafeInforAppendAttachDTO){
        return AjaxResult.success(bizSafeInforService.relateAttaches(bizSafeInforAppendAttachDTO));
    }
    /**
     * 上传安全内业资料文件（追加）
     * @param bizSafeInforAppendAttachDTO
     * @return
     */
    @PostMapping("/appendAttaches")
    public AjaxResult appendAttaches(@RequestBody @Validated BizSafeInforAppendAttachDTO bizSafeInforAppendAttachDTO){
        return AjaxResult.success(bizSafeInforService.appendAttaches(bizSafeInforAppendAttachDTO));
    }

    /**
     * 覆盖原有的安全内业资料文件
     * @param bizSafeInfoCoverAttachDTO
     * @return
     */
    @PostMapping("/coverAttach")
    public AjaxResult coverAttach(@RequestBody @Validated BizSafeInfoCoverAttachDTO bizSafeInfoCoverAttachDTO){
        return AjaxResult.success(bizSafeInforService.coverAttache(bizSafeInfoCoverAttachDTO));
    }

    /**
     * 安全内业资料文件列表
     * @param bizSafeInforFileListDTO
     * @return
     */
    @GetMapping("/fileList")
    public AjaxResult getFileList(@ModelAttribute @Validated BizSafeInforFileListDTO bizSafeInforFileListDTO){
        startPage();
        List<BizSafeDocAttachVO> bizSafeDocAttaches = bizSafeInforService.selectFileList(bizSafeInforFileListDTO);
        clearPage();
        return AjaxResult.success(getDataTable(bizSafeDocAttaches));

    }
}
